package com.wiscamp.ninechapters.panels.infrastructure.mappers;

import com.wiscamp.ninechapters.panels.infrastructure.views.UserView;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Component;

import java.util.Collection;

@Component
public interface UserViewMapper extends JpaRepository<UserView, Long>, JpaSpecificationExecutor<UserView> {

    @Query(value = "select p from UserView p where p.applicationId = :appId and p.userCode = :userCode")
    UserView findByUserCode(long appId, String userCode);

    @Query(value = "select p from UserView p where p.applicationId = :appId and p.userName = :userName")
    Collection<UserView> findListByUserName(long appId, String userName);

    Page<UserView> findAll(Specification<UserView> specification, Pageable pageable);
}
